package Offer;

import java.util.Stack;

//20.表示数值的字符串
//这题纯傻逼，别做了
public class Offer20 {
    public boolean isNumber(String s) {
        s=s.strip();
        if(s.length()==0)return false;
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if(c>=48&&c<=57){
                stack.push(c);
                continue;
            }
            switch (c){
                case '+':
                case '-':
                    if(i==s.length()-1)return false;
                    if(stack.empty()){
                        stack.push(c);
                    }else {
                        char peek = stack.peek();
                        if(peek=='E'||peek=='e')
                            stack.push(c);
                        else return false;
                    }
                    break;
                case 'E':
                case 'e':
                    if(stack.empty())return false;
                    if(i==s.length()-1)return false;
                    stack.removeElement('.');
                    char pk = stack.peek();
                    if(pk<48||pk>57)return false;
                    stack.push(c);
                    break;
                case '.':
                    if(s.length()==1)return false;
                    if(stack.contains('.'))return false;
                    if(stack.empty()){
                        stack.push(c);
                        break;
                    }
                    char peek = stack.peek();
                    if(peek=='E'||peek=='e')
                        return false;
                    stack.push(c);
                    break;
                default:
                    stack.push(c);
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Offer20 offer20 = new Offer20();
        System.out.println(offer20.isNumber("1e2."));
    }
}
